class LoadMore{
	   Initialization(params){
			var self = this;
			this.ele = params.ele;
			this.method=params.method
			this.url=params.url
			this.page=params.page
			this.data=params.data
			this.list = params.list;
			this.success = params.success;
			this.start();
			if(typeof self.Operating=="function"){
				self.Operating()
			}
		}
		start() {
			var self = this;
			$(self.ele).each(function(index, element) {
                var T=$(this);
                  $(window).bind('scroll', function() {
					  var url=self.url;
				      var method=self.method;
					  var page=self.page;
					  var data=self.data
                      if($(document).scrollTop() + $(window).height() >= $(document).height()-50) {
				              if(page > 1 &&!$(self.ele).hasClass("on")) {
								$(self.ele).addClass("on");
								//$(".lm_load_more").show()
                                $.ajax({
                                        type: method?method:"post",
                                        url: url,
                                        data:  Object.assign({page:page},data),
                                        dataType: "json",
                                        success: function(e) {
										    if(typeof self.success=="function"){
											   self.success(e,page)
											   if(e.hasMore==true){
												setTimeout(function(){$(self.ele).removeClass("on")},200);
											   }
											}
											
                                         },
                                         error: function(XMLHttpRequest, textStatus, errorThrown) {
                                                alert(errorThrown);
                                         }
                                   });
                             }
                         }
                 });
				
            });
			this.autoMore()
		    $("body,html").animate({"scrollTop":0},0)
	}
	autoMore(){
		let self=this
		var url=this.url;
		var method=this.method;
		var page=parseInt(this.page);
		var data=this.data
		  if(page==1){
				$.ajax({
				  type: method?method:"post",
				  url: url,
				  data: Object.assign({page:page},data),
				  dataType: "json",
				  success: function(e) {
					 if(typeof self.success=="function"){
							  self.success(e,page)
					  }
					  setTimeout(function(){$(this.ele).removeClass("on")},200);
				   },
				   error: function(XMLHttpRequest, textStatus, errorThrown) {
							  alert(errorThrown);
				   }
			 });
	   }
    }    
}
	

export {LoadMore}